<template>
  <div class="container">
    <navBar :title="'安全措施评估'" :backStep="'myToDoList'"></navBar>
    <!-- <topForm></topForm> -->
    <topForm :code="code" :formInfoObj="formInfoObj" :wordId="wordId"></topForm>

    <div class="workTitle">安全措施评估</div>

    <div class="formBox">
      <!-- <div class="formItem">
        <van-cell title="措施指定人:">
          <template #default>
            {{ formInfoObj.measureOpinion?.[0].peopleName }}
          </template>
        </van-cell>
      </div> -->

      <div class="formItem">
        <div class="cellCss">
          <div class="cellCssTitle">危险源辨识:</div>
          <div>
            <van-checkbox-group
              direction="horizontal"
              shape="square"
              v-model="check"
            >
              <van-checkbox
                shape="square"
                v-for="item in workMethodOptions"
                :key="item.id"
                :name="item.name"
                >{{ item.name }}</van-checkbox
              >
            </van-checkbox-group>
          </div>
        </div>
      </div>

      <div class="formItem" v-for="item in measureList" :key="item.id">
        <div class="cellCss">
          <div class="cellCssTitle">{{ item.content }}:</div>
          <div class="cellCssContent">
            <div class="left">
              <!-- 确认人：<span style="color: #b2b6bc" @click="chooseName"
                >张三 ></span
              > -->
            </div>
            <div class="right">
              涉及：<van-switch size="25" v-model="item.isture" />
            </div>
          </div>
        </div>
      </div>
    </div>
    <van-goods-action>
      <van-goods-action-button
        :style="{
          background: '#0077FF',
          color: '#fff',
        }"
        type="danger"
        text="提交"
        @click="onClickButton"
      />
    </van-goods-action>
  </div>
</template>

<script>
import { getOneApi, ticketUpdateApi } from '@/api/ticket'
import {
  riskIdentificationListApi,
  securityMeasureListApi,
} from '@/api/dictionary'

import '@/css/form.scss'

import navBar from '@/components/navBar.vue'
import topForm from './components/topForm'
export default {
  name: 'safetyMeasure',
  props: {},
  components: {
    navBar,
    topForm,
  },
  data() {
    return {
      formInfo: {
        jobName: '',
      },
      workMethod: ['a'],
      checked: false,
      formInfoObj: {},
      workMethodOptions: [],
      check: [],
      measureList: [],
    }
  },
  created() {
    this.wordId = this.$route.query.id
    this.code = this.$route.query.code
    this.codeName = this.$route.query.codeName
    this.getOneApi()
    this.isLoginMsg = JSON.parse(sessionStorage.getItem('loginInfo'))
  },
  methods: {
    async onClickButton() {
      const data = {
        status: 2,
        id: this.formInfoObj.id,
        measureOpinion: [
          {
            peopleName: this.formInfoObj.measureOpinion[0].peopleName,
            peopleID: this.formInfoObj.measureOpinion[0].peopleID,
            peopleStatus: 1,
          },
        ],
        measureList: this.measureList.map((item) => {
          return {
            isture: item.isture == true ? 0 : 1,
            content: item.name,
          }
        }),
        analysisDanger: this.check.join(),
      }

      const res = await ticketUpdateApi(data)
      console.log(res)
      if (res.code == 0) {
        this.$router.push({
          path: '/myToDoList',
        })
      }
    },
    chooseName() {},
    async getOneApi() {
      const res = await getOneApi({ id: +this.wordId })
      this.formInfoObj = res.data
      const res2 = await riskIdentificationListApi({
        ticketTypeCode: this.code,
      })
      this.workMethodOptions = res2.data

      const res3 = await securityMeasureListApi({
        ticketTypeCode: this.code,
      })
      this.measureList = res3.data.map((item) => {
        return {
          ...item,
          isture: true,
          content: item.name,
        }
      })
      
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
}
</script>

<style scoped lang="scss">
.container {
  background-color: #f5f6f7;
  width: 100%;
  height: 100%;
  padding: 16px;
  box-sizing: border-box;
  padding-bottom: 60px;
}
</style>
